package com.lovo.ssc.controller;


import com.lovo.ssc.dto.OrderDto;
import com.lovo.ssc.entity.Customer;
import com.lovo.ssc.entity.Ordergoods;
import com.lovo.ssc.entity.SysOrder;
import com.lovo.ssc.service.ISysOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author lovo
 * @since 2022-07-08
 */
@RestController
@RequestMapping("/sys-order")
@Api(tags = "订单控制层002卢虹兵")
public class SysOrderController {

    @Autowired
    ISysOrderService orderService;

    @PostMapping("saveOrder")
    @ApiOperation(value = "添加订单")
    public int saveOrder(SysOrder order){
        return orderService.addOrder(order);
    }

    @GetMapping("findAll")
    @ApiOperation(value = "查询全部订单")
    public List<OrderDto> findAll(){
        return orderService.findAll();
    }

    @GetMapping("findByItem")
    @ApiOperation(value = "动态查询")
    public List<OrderDto> findByItem(String type, String startTime, String endTime){
        return orderService.findByItem(type, startTime, endTime);
    }

    @GetMapping("findById/{orderId}")
    @ApiOperation(value = "根据订单ID查询商品")
    public List<Ordergoods> findById(@PathVariable("orderId") int orderId){
        return orderService.findById(orderId);
    }

    @GetMapping("findByUserName/{userName}")
    @ApiOperation(value = "根据客户名查询客户信息")
    public Customer findByUserName(@PathVariable("userName") String userName){
        return orderService.findByUserName(userName);
    }
}
